<?php
$q=$_GET["q"];
$hint='<br/><br/><br/><font color="black">These are the results of your search,please find a link to view the details of the matching search text <br/>';
include_once ("Login/databaseconnection.php");
require_once ("Login/config.php");
$dbname = $db;
$sql ="SHOW TABLES FROM $dbname";
$resulttable = mysql_query($sql);
while($rowtable = mysql_fetch_row($resulttable))
{
if($rowtable[0]!="user"&&substr($rowtable[0],0,4)!="dele")
{
$que="SHOW COLUMNS FROM $rowtable[0]";
$resultcol=mysql_query($que);
while ($rowcol= mysql_fetch_row($resultcol))
{
if(substr($rowtable[0],0,3)=="del")
{
$getque="SELECT * FROM $rowtable[0] WHERE ".$rowcol[0]." LIKE '%$q%'";
}
else
{
$getque="SELECT * FROM $rowtable[0] WHERE ".$rowcol[0]."='$q'";
}

$result=mysql_query($getque);
if($result)
{
if($roww=mysql_fetch_array($result))
{
if($roww[$rowcol[0]]!="0")
{
if(mysql_num_rows($result)!=0)
{
 $column=str_replace("_"," ",$rowcol[0]);
  $hint=$hint.'Your keyword is found as the <a href="'.$basedir.'/index.php?t='.$rowtable[0].'&c='.$rowcol[0].'&v='.$q.'" class="searchlinks">'.$column.'</a>';
 if(mysql_num_rows($resultcol)==2)
{
$sqlpri = "SHOW INDEX FROM $rowtable[0] WHERE Key_name = 'PRIMARY'";
$getprimekey= mysql_query($sqlpri);
$cgp = mysql_num_rows($getprimekey);
if($cgp > 0){
$agp = mysql_fetch_array($getprimekey);
extract($agp);
$cn=str_replace("_"," ",$Column_name);
$que="SHOW COLUMNS FROM $rowtable[0]";
$resultcol=mysql_query($que);
while($rowcol= mysql_fetch_row($resultcol))
{
if($rowcol[0]!=$Column_name)
{
$otherfie=$rowcol[0];
$otherfield=str_replace("_"," ",$otherfie);
}
}
$sq=mysql_query("SELECT * FROM $rowtable[0]");
$colval="";
while ($rowcl= mysql_fetch_array($sq))
{
$colval=$colval.$rowcl[$otherfie];
}
$hint=$hint.'<font color="black"> of </font><font color="#003366">'.$rowtable[0].'(contains the '.$otherfield.'s of the '.$cn.'s)</font>';
$tiofre=substr_count($colval,$q); 
if($tiofre>0)
{
$hint=$hint.'<font color="black"> This link will view the '.$cn.'  of the '.$q.'</font>';
}
if($tiofre==0)
{
$hint=$hint.'<font color="black"> This link will view the '.$otherfield.' of the '.$q.'</font>';
}
}
 }
 else
 {
 $hint=$hint.'<font color="black"> of </font><font color="#003366">'.$rowtable[0].'</font>';
 $hint=$hint.'<font color="black"> This link provides the details of the key value that you have selected.</font><br/> ';
 }
}
}
}
}
}
}
$hints= explode(" ",$hint);
$s=$hints[count($hints)-1];
if($s!="<br/>")
{
$hint=$hint."<br/>";
}
}
if($hint=='<br/><br/><br/><font color="black">These are the results of your search,please find a link to view the details of the matching search text <br/>')
{
$response='<br/><br/><br/><img src="images/alert.jpg" width="12" height="12"/><font color="red">Sorry unable to find the results for your key word <br/>';
}
else
{
$response=$hint;
}
echo $response;
?>